l = [9, 8, 7, 6, 5, 4, 3, 2, 1]
l1 = [1, 3, 2, 5, 3]  #5
n = len(l)  #9

while n > 0:
    i = 0
    while l[i] > l[i + 1]:
        l[i], l[i + 1] = l[i + 1], l[i]
        i += 1
        if (i == len(l)-1):
            break
    i = 0
    n -= 1

print(l)

# 方法2
def bull_sort(l):
    for i in range(len(l)):
        for e in range(len(l)-1-i):
            if l[i] > l[i+1]:
                l[i], l[i+1] = l[i+1], l[i]

    return l

print(bull_sort(l1))